<script type="text/javascript" src="/public/library/ckeditor/ckeditor.js"></script>

<?
	$sess = new Zend_Session_Namespace(CLU_NS);
//	  die($sess->userPermissions);
?>
<style type="text/css">
.gray-bg
{
	background-color : #c8cbd6;
}
</style>
<script type="text/javascript" charset="utf-8">
$(function(){
		$("#submit_comment").click(function(){
			$("#productAjaxForm").submit();
			return false;
		});
	
		$("#productAjaxForm").ajaxForm({
            dataType: 'json',
            success: function(json)
            {
            	if(json.success)
            	{
	            	window.location.reload();					
					return false;
            	}
            	else
            		return false;
            }
        });
});
</script>
       <div style="background-color:#ffffff">
         <div id="region9_wapper">
         <div class="product_namelist" >Danh sach san pham cua doanh nghiep</div>
         <div class="clear"></div>
		 <br />		 
		 <? if(isset($this->viewParams['productList'])):?>
		 <? $i =1;?>
		 
		 <script type="text/javascript" src="/public/library/jquery/prettyPhoto/jquery.prettyPhoto.js"></script>
        <link rel="stylesheet" href="/public/library/jquery/prettyPhoto/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
		 
		 <? foreach($this->viewParams['productList'] as $p) :?>
		  <div class="mouse_action-<?=$p['id']?> product_list">
		  
		  <div class="product_img">
		  <? if(isset($p['images'])):?>
		  <? $images = explode(';', $p['images']) ?>
		  <a href="<?=str_replace("/original/", "/medium/", $images[0])?>" rel="prettyPhoto[product<?=$p['id']?>]" > <img src="<?=str_replace("/original/", "/small/", $images[0])?>" align="absmiddle" /></a>
		  <? $total = count($images);?>
		  <? $j = 1; ?>
		  <?if($total > 2 ) :?>
		  <? foreach($images as $m) :?>
		  <div style="display: none">
		  <a href="<?=str_replace("/original/", "/medium/", $images[$j])?>" rel="prettyPhoto[product<?=$p['id']?>]" > <img src="<?=str_replace("/original/", "/small/", $images[$j])?>" align="absmiddle" /></a>
		  </div>
		  <? if($j >= $total-2) break;?>
		  <? $j++;?>
		  <?endforeach?>
		  <?endif?>
		  <?endif?>
		  <script type="text/javascript" charset="utf-8">
			$(function(){
					$('.uploadForm').openDOMWindow({ 
			            height:'80', 
			            width:'450', 
			            positionType:'centered', 
			            positionTop:250, 
			            eventType:'click', 
			            positionLeft:'100', 
			            windowSourceID:'#uploadImage<?=$i?>', 
			            windowPadding:'5', 
			            /*draggable:1,*/ 
			            windowBGColor:'#FFFFFF', 
			            borderColor:'#243e89',
			            borderSize: '12' 
			         //   overlayOpacity:'40', 
			     });    
			});
			</script>
			 <?if ((isset($sess->userId) && (strpos($sess->userPermissions, 'administer everything') ||
		                   ($sess->userId == $this->viewParams['user_id'] && strpos ($sess->userPermissions, 'create product')
		                        )))):?>
		 <br/><a href="#uploadImage<?=$i?>" id="#uploadImage<?=$i?>" class="uploadForm">upload image</a>
		     <?endif?>
		 </div>
			<div id="uploadImage<?=$i?>" style="display: none;color: gray;" align="center">
			<br/><br/>
	          	<div class="box white_bg">
				<form enctype="multipart/form-data" action="/<?=$sess->viewLang?>/product/master/upload-img-product" method="POST" class="a_form">
					<label for="example1_field">Choose a file to upload: </label>
					<input name="id" value="<?=$p['id']?>" type="hidden" /> 
					<input name="MAX_FILE_SIZE" value="5048576" type="hidden" />
					<input name="poster_id" value="<?=$p['user_id']?>" type="hidden" />
					<input name="myFile"  type="file"  id="myFile"   value=""/>
					<input type="submit" value="Send" id="submit_upload" />
				</form>
				</div>  
            </div> 
			<div class="product_list_title">
			<div class="product_title"><a href="<?=$this->hvnUrl(array('module' => 'user','controller'=>'account', 'action' => 'view-product'),'generic')?>?id=<?=$this->viewParams['user_id']?>&product_id=<?=$p['id']?>"><?=$p['title']?></a></div>
			<div class="product_price">Giá : <?=$p['price']?></div>
			</div>
			<div class="product_description"><?=$p['desc']?></div>
			<div class="clear"></div>
			
			<div style="height:30px;width:400px; padding: 2px 0 0;">
				 <!-- class = "tr-action" -->
		        <div align = "right"  >
		        <?if ((isset($sess->userId) && (strpos($sess->userPermissions, 'administer everything') ||
		                   ($sess->userId == $this->viewParams['user_id'] && strpos ($sess->userPermissions, 'update own product')
		                        )))):?>
		        <a id="#productForm" href="<?=$this->hvnUrl(array('module' => 'product', 'action' => 'edit'),'nocontroller')?>?id=<?=$p['id']?>&user_id=<?=$this->viewParams['id']?>"><?=t(38)?> </a>|
		        <?endif?>
		        <?if ((isset($sess->userId) && (strpos($sess->userPermissions, 'administer everything') ||
		                   ($sess->userId == $this->viewParams['user_id'] && strpos ($sess->userPermissions, 'delete own product')
		                      )))):?>
		    <a href="javascript:void()" name="item-delete-product-<?=$p['id']?>"><?=t(31)?></a>
		     <?endif?>
		        </div>
		    </div>
    
        <div class="clear"></div>
		</div>
		<? $i++; ?>
		<?endforeach?>
	    <?endif?>
		   
		<div class="clear"></div>
		 <?if ((isset($sess->userId) && (strpos($sess->userPermissions, 'administer everything') ||
		                   ($sess->userId == $this->viewParams['user_id'] && strpos ($sess->userPermissions, 'create product')
		                        )))):?>
		   <div class="product_add">
		      <div class="product_add_buttom"><a href="#productForm" id="#productForm" class="productDOMWindow">+</a></div>
		   </div>
		        <?endif?>
		        
		   
 <div class="clear"></div>
          </div>
          
	<div id="productForm" style="display: none;color: gray;" align="center">
	<form id="productAjaxForm" accept-charset="UTF-8" action="/<?=$sess->viewLang?>/product/ajax/list" method="POST">
	<input type="hidden" name="id" value="<?=$this->viewParams['id']?>" ></input>
	<?=t(13)?> :
	<?=$this->viewParams['form']->title;?>
	<br/>
	<?=t(811)?> :
	<?=$this->viewParams['form']->price;?>
	<br/>
	<?=t(21)?> :
	<?=$this->viewParams['form']->desc;?>
	<br/>
	<?=$this->viewParams['form']->submit;?>
	</form>
	</div>
</div>
<script type="text/javascript">
	$("a[rel^='prettyPhoto']").prettyPhoto();
</script>
<script type="text/javascript">
$(function(){
	
$('.productDOMWindow').openDOMWindow({ 
                        height:'450', 
                        width:'550', 
                        positionType:'centered', 
                        positionTop:250, 
                        eventType:'click', 
                        positionLeft:'100', 
                        windowSourceID:'#productForm', 
                        windowPadding:'5', 
                        /*draggable:1,*/ 
                        windowBGColor:'#FFFFFF', 
                        borderColor:'#243e89',
                        borderSize: '12', 
                     //   overlayOpacity:'40', 
 	});
});

</script>

<script type="text/javascript">
	//	var editor = CKEDITOR.replace( 'desc',	{toolbar: 'Basic'}
		//					 );
</script>
<script type="text/javascript">
$(function() {
    $("[class^=mouse_action]").mouseover(function(e){
                        $(this).find(".tr-action").show();
                        $(this).find(".product_list").addClass("gray-bg");
                }).mouseout(function(){
                        $(this).find(".tr-action").hide();
                        $(this).find(".product_list").removeClass("gray-bg");
                });
    
	$("[name^=item-delete-]").click(function(e){
		var del=confirm("Do you want to delete this item?");
		deleteId = this.name.split('-')[3];
		//type = this.name.split('-')[2];
		messeage = '';
		if (del){	
				$.getJSON("/<?=$sess->viewLang?>/product/ajax/delete-product", 
						 {id: deleteId},
						 function(json) {
							if(json.success)	
								$(".mouse_action-"  + deleteId).css('background-color','red').fadeOut(2000);
			               	else
			               		$(".mouse_action-"  + deleteId).show().html("<?=t(729)?>");
			               return false;
				});
		}else
			return false;
	});
});
</script>

